package leetcode.code1267;

public class Solution {
	public int countServers(int[][] grid) {
		int m = grid.length, n = grid[0].length;
		int[] mm = new int[m];
		int[] nn = new int[n];
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				int cur = grid[i][j];
				if (cur == 1) {
					mm[i]++;
					nn[j]++;
				}
			}
		}
		int ans = 0;
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				int cur = grid[i][j];
				if (cur == 1) {
					if (mm[i] > 1 || nn[j] > 1) {
						ans++;
					}
				}
			}
		}
		return ans;
	}
}
